package Vue;

import Controleur.ControlePartie;
import javax.swing.JOptionPane;

/**
 * Fenêtre permettant de gérer la fin de la partie
 * @author El Meknassi Hamza (10806466) - Migeon Cyril (11007322)
 */
public class FinPartieVue extends javax.swing.JFrame {

    //Référence sur le controleur
    private ControlePartie controleur;

    /**
     * Constructeur de la frame
     * @param nomJoueur
     * @param controleur
     */
    public FinPartieVue(String nomJoueur, ControlePartie controleur) {
        initComponents();
        this.controleur = controleur;
        labelGagnant.setText("  "+nomJoueur+" a gagné");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelTitre = new javax.swing.JLabel();
        labelGagnant = new javax.swing.JLabel();
        rejouterBouton = new javax.swing.JButton();
        quitterBouton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setAlwaysOnTop(true);
        setResizable(false);

        labelTitre.setFont(new java.awt.Font("Monospaced", 1, 24)); // NOI18N
        labelTitre.setText("FIN DE LA PARTIE");

        labelGagnant.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N

        rejouterBouton.setText("Rejouer");
        rejouterBouton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rejouterBoutonActionPerformed(evt);
            }
        });

        quitterBouton.setText("Quitter");
        quitterBouton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitterBoutonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rejouterBouton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
                        .addComponent(quitterBouton))
                    .addComponent(labelTitre)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(labelGagnant)))
                .addGap(27, 27, 27))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(labelTitre)
                .addGap(47, 47, 47)
                .addComponent(labelGagnant)
                .addGap(41, 41, 41)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rejouterBouton)
                    .addComponent(quitterBouton))
                .addContainerGap(61, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rejouterBoutonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rejouterBoutonActionPerformed
        // TODO add your handling code here:
        controleur.rejouer();
    }//GEN-LAST:event_rejouterBoutonActionPerformed

    private void quitterBoutonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitterBoutonActionPerformed
        // TODO add your handling code here:
        int reponse = JOptionPane.showConfirmDialog(this, "Etes-vous sur de vouloir quitter l'application ?", "Quitter", JOptionPane.YES_NO_OPTION);
            if(reponse==JOptionPane.YES_OPTION)
                System.exit(0);
    }//GEN-LAST:event_quitterBoutonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel labelGagnant;
    private javax.swing.JLabel labelTitre;
    private javax.swing.JButton quitterBouton;
    private javax.swing.JButton rejouterBouton;
    // End of variables declaration//GEN-END:variables

}
